#!/usr/bin/perl
# March 10, 2009. Updated for Oracle 10g
# Modified from proC++v10 ... path changed, lib 32 driver changed

# How to compile a pro c / proc++? Source files end with .pc 
#proC++v10 fileName  //fileName.pc is in the account

$noArg = $#ARGV+1;
die "usage:  $0 cxxFileName   OR   $0 ccFileName cc 
Note:   Source file extension should be .pc!\n" if (  $noArg < 1) ;


$_ = $ARGV[0];
die "Note: Source file in dir should have extension  .pc!
However, invoke proC++v10 WITHOUT the '.pc' source file extension! 
Example: proC++v10 fileName           //fileName.pc is source file \n"
                if (  /.*\.pc/) ;


`/bin/rm -f $fileNameo , $fileNamec  `;
$true = 1; $false = 0; $cxxcompiler = $true;
$compiler = 'CC';
$cxxcompiler = $true;

$fileName  = $ARGV[0]; 
$fileNamec = $fileName . '.c'; 
$fileNameo  = $fileName . '.o';
$fileNamepc = $ARGV[0] . '.pc';

#`/bin/chmod 755  $fileNamepc  `;

#$extraproCplus  
#	=  ' code=cpp sys_include=\'(/usr/include/cxx,/usr/include)\'' ; }
$extraproCplus  =  ' code=cpp ' .  ' \'sys_include=' .
	'(/opt/SUNWspro4.2/SUNWspro/SC4.2/include/CC,/usr/include)\'' ; 

`proc  $extraproCplus  iname=$fileName  `;  
#print "$extraproCplus \n above are proc options\n";

$x1 = '-I/usr/local/oracle/u00/app/oracle/product/10.2.0/db/precomp/public ';
$x2 = '-I/usr/local/oracle/u00/app/oracle/product/10.2.0/db/rdbms/public ';
$x3 = '-I/usr/local/oracle/u00/app/oracle/product/10.2.0/db/rdbms/demo ';
$x4 = '-I/usr/local/oracle/u00/app/oracle/product/10.2.0/db/plsql/public ';
$x5 = '-I/usr/local/oracle/u00/app/oracle/product/10.2.0/db/network/public '; 
$x6 = $fileNamec ;

$xlib1 =  $x1 . $x2 . $x3 . $x4 . $x5  . $x6 ;

$extra = '-w -c -I. ';

$x  = $extra . $xlib1 ; 

#print "$x \nabove are First CC options\n";
`$compiler $x   `;  


$z6a = ' -L/usr/local/oracle/u00/app/oracle/product/10.2.0/db/lib32 '   ;
$z7a = ' -lclntsh ' ;
$z7 = `cat /usr/local/oracle/u00/app/oracle/product/10.2.0/db/lib32/sysliblist` ; 
chop ($z7);
$z7b = ' -R/usr/local/oracle/u00/app/oracle/product/10.2.0/db/lib32 '   ;
$z8a = ' -laio ' ;
$z8b = ' -lm ' ;

$Z  = $z6a. $z7a . $z7 . $z7b . $z8a . $z8b ;
#print "\n\n $Z \nabove are Second CC options\n";

#`/usr/bin/echo $Z  `;

`$compiler    -o $fileName $fileNameo $Z   `;  

#`/bin/rm -f $fileNameo , $fileNamec  `;
